//=========================================================================
// Copyright (C) 2023 The C++ Component Model(COMO) Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//=========================================================================

#ifndef __Bitmap_H_INCLUDED__
#define __Bitmap_H_INCLUDED__

// use dynamic allocation with these functions
// compile with -DBitmap_64 to force 64-bit words
// compile with -O [dash capital o] for more efficient machine code

#ifdef Bitmap_64
    #define Bitmap_type unsigned long long int
#else   // assumed to be 32 bits
    #define Bitmap_type unsigned int
#endif

typedef struct tagBitmap {
    int bits;     // number of bits in the array
    int words;    // number of words in the array
    bool greedy;  // Did we take ownership of data?
    Bitmap_type *array;
} Bitmap;

void Bitmap_Set(Bitmap *b, int n);      // n is a bit index
void Bitmap_Clear(Bitmap *b, int n);
int Bitmap_Read(Bitmap *b, int n);
int Bitmap_Find(Bitmap *b);             // find bit 0, return bit index
Bitmap *Bitmap_Allocate(int bits, Bitmap_type *array, int array_size);
void Bitmap_Deallocate(Bitmap *b);

#endif
